
/**
 * The Projectile class creates a Projectile object that extends MovableEnt
 * 
 * @author      Zachary Bellido
 * @version     0.01
 */
import java.awt.*;
import java.awt.geom.*;

public class Projectile extends MovableEnt implements StepInterface
{
    // instance variables - replace the example below with your own
    private Point2D.Double myCoord;
    private char mySymbol;
    private int health;
    private int direction;   //0 = up, 1 = right, 2 = down, 3 = left
    private boolean diagonalBool;

    /**
     * Constructor for objects of class Projectile
     */
    public Projectile(char symbol, int coordX, int coordY, int d){
        // initialise instance variables
        super(symbol, coordX, coordY);
        direction = d;
        if (Runner.player.getNumProjectiles() > 0)
        {
            Runner.player.useProjectiles(1);
            Grid.queueEntAddition(this);
        }
    }

     /**
     * Preform actions every timer tick
     * 
     * @pre     object must be initialized     
     * @param   none
     * @return  none
     * @post    none    
     */
    public void step(){

        int prevX;  //the x coord before step
        int prevY;  //the y coord before step
        prevX = getCoordX();
        prevY = getCoordY();
        
        //Same procedure as moving players.
        int controlVertical = 0;
        int controlHorizontal = 0;
        if (direction == 0){
            controlVertical--;
        }
        else if (direction == 2){
            controlVertical++;
        }
        else if (direction == 3){
            controlHorizontal--;
        }
        else if (direction == 1){
            controlHorizontal++;
        }
        else if (Math.abs(controlVertical) + Math.abs(controlHorizontal) > 1){
            diagonalBool = !diagonalBool;
            if (diagonalBool)
                controlHorizontal = 0;
            else
                controlVertical = 0;
        }
        move(controlHorizontal, controlVertical);
        //Check to see if the projectile hit something.
        if(prevX == getCoordX() && prevY == getCoordY()){
            GridEntity ent = Grid.getEntAt(prevX + controlHorizontal, prevY + controlVertical);
            //Check to see if it hit an enemy.
            if (ent instanceof Enemy)
                ent.remove();
            remove();
        }
    }
}
